package top.jamsee.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;
import top.jamsee.dao.LentDao;
import top.jamsee.dao.RegisterHouseDao;
import top.jamsee.entity.Lent_data;
import top.jamsee.entity.RegisterHouse;
import top.jamsee.service.RegisterHouseService;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class RegisterHouseServiceImpl implements RegisterHouseService {
    @Resource
    private RegisterHouseDao dao;

    @Override
    //查询租房表的数据
    public List<List> SelectRegisterHouseData(int pageNum) {


        //当前页数
//        System.out.println(p.getPageNum());
        //获取全部页数
        //每页的大小
//        System.out.println(p.getPageSize());
        //总页数
        Page p= PageHelper.startPage(pageNum,20);
        List<RegisterHouse> registerHouse_data=dao.selectRegisterHouseData();
        //算出多少页=全部多少行,每页多少条
        int colunms=dao.selectRegisterHouseNum();
        int pages=colunms/20;

        List<List> ls=new ArrayList<List>();
        List<Integer> pageList=new ArrayList<Integer>();
        pageList.add(pages);
        ls.add(registerHouse_data);
        ls.add(pageList);




        //返回

        return ls;
    }
    @Override
    //删除租房表的数据
    public int deleteRegisterHouseData(int id){
        int res=dao.deleteRegisterHouseDataById(id);//
        System.out.println("结果是"+res);
        return res;
    }

    @Override
    public int selectRegisterHouseNum() {
        return dao.selectRegisterHouseNum();
    }

    //添加一条记录(需要操作两个表 需要事务)
    public int addRegisterHouseData(RegisterHouse registerHouse){


        dao.addRegisterHouseData(registerHouse);


        return 1;
    }

    @Override
        //模糊查询buy表
        public List selectRegisterHouseByData(int pageNum,String contact_name) {


            //当前页数
//        System.out.println(p.getPageNum());
            //获取全部页数
            //每页的大小
//        System.out.println(p.getPageSize());
            //总页数
            Page p=PageHelper.startPage(pageNum,20);
        List<RegisterHouse> registerHouse_data=dao.selectRegisterHouseByData(contact_name);
        //算出多少页=全部多少行,每页多少条
        int colunms=dao.selectRegisterHouseByNum(contact_name);
        int pages=colunms;

        List ls=new ArrayList();
        ls.add(registerHouse_data);
        ls.add(pages);



        //返回
        return ls;


    }
    @Override
    //模糊查询lent表的所有数量方便后续分页
    public int selectRegisterHouseByDataNum(String contact_name){

        return dao.selectRegisterHouseByNum(contact_name);
    }
    @Override
    //更新lent表根据id
    public boolean upDateRegisterHouseById(RegisterHouse registerHouse){
        //更新后得到更新条数
        int num=dao.upDateRegisterHouseById(registerHouse);
        //大于10说明更新成功
        if (num>0){
            return true;
        }else {
            return false;
        }

    }
    @Override
    //根据id查询是否有此条记录,更新表时使用
    public int selectRegisterHouseById(int id){ return dao.selectRegisterHouseById(id); }


}
